#!/bin/bash
mem=`/sbin/sysctl -n kernel.shmall`
min=4294967296
if [ ${#mem} -le ${#min} ]; then
    if [ $mem -lt $min ]; then
    echo "kernel.shmall too low, setting to 4G pages = 16TB"
    /sbin/sysctl -w kernel.shmall=$min
    fi
fi

mem=`/sbin/sysctl -n kernel.shmmax`
min=1073741824
if [ ${#mem} -le ${#min} ]; then
    if [ $mem -lt $min ]; then
    echo "kernel.shmmax too low, setting to 1GB"
    /sbin/sysctl -w kernel.shmmax=$min
    fi
fi

set_socket_buffer_limit() {
	name=${1}; path=${2}; size=${3}
	curr=$(cat ${path})

	if [ ${curr} -lt ${size} ]; then
		echo "Increasing ${name} socket buffer limit (${path}): ${curr} -> ${size}"
		echo ${size} >${path}
	fi
}

set_socket_buffer_limit read /proc/sys/net/core/rmem_max 15728640
set_socket_buffer_limit write /proc/sys/net/core/wmem_max 5242880

if [ -f /etc/aerospike/initfns ]
then
    . /etc/aerospike/initfns
fi
